from PIL  import Image,ImageDraw,ImageFont
#                 mode      size       color
image = Image.new("RGB",(900,540),(255,255,255))
#                    img  mode
draw = ImageDraw.Draw(image)
#
font = ImageFont.truetype('msyhl.ttc',size=45)

import random
import qrcode
import datetime

print("=" *50)
print("{:^50}".format("社区出入证生成"))
print("=" *50)

print("\n\n所有数据项均为必填")
(x,y) = (50,40)
message = input("\n社区：")
community = message
color = 'rgb(0,0,0)'
font = ImageFont.truetype('msyhl.ttc',size=80)
draw.text((x,y),community,fill=color,font=font)

(x,y) = (500,65)
idno = random.randint(10000000,90000000)
message = str('ID'+str(idno))
color = 'rgb(0,0,0)'
font = ImageFont.truetype('msyhl.ttc',size=60)
draw.text((x,y),message,fill=color,font=font)

(x, y) = (50, 220)
message = input('姓名：')
name = message
color = 'rgb(0,0,0)'
font = ImageFont.truetype('msyhl.ttc',size=45)
draw.text((x,y),f"姓名：{name}",fill=color,font=font)

(x, y) = (50, 320)
message = input("性别：")
gender = f"性别：{message}"
color = 'rgb(0,0,0)'
draw.text((x,y), gender, fill=color, font=font)

(x, y) = (50, 420)
message = input("门牌： ")
house = f"门牌： {message}"
draw.text((x,y), house, fill=color, font=font)

image.save(str(name)+".png")
# img = qrcode.make(f"{community}:{name}")
img = qrcode.make(f"{community}:{name}")
img.save(str(idno)+".bmp")

til = Image.open(name+".png")
im = Image.open(str(idno)+".bmp")
til.paste(im,(520,180))
til.save(name+".png")

print("\n\n\n您的出入证成功创建于图片文件"+ name + ".png")